package org.example;


import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController // 表示该类为控制器
public class RequestController {

    @RequestMapping("/request") // 表示请求路径
    public String rquest(HttpServletRequest request) {
        // 1. 获取请求方式
        String method = request.getMethod();
        System.out.println("获取请求方式method : "+method);

        // 2. 获取请求url地址
        String url = request.getRequestURL().toString();
        System.out.println("获取请求url地址url : "+url);
        String uri = request.getRequestURI();
        System.out.println("获取请求url地址uri : "+uri);

        // 3. 获取请求协议
        String protocol = request.getProtocol();
        System.out.println("获取请求协议protocol : "+protocol);

        // 4. 获取请求参数 - name , age
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        System.out.println("获取请求参数 - name , age : "+name+" , "+age);

        // 5.获取请求头 - Accept
        String header = request.getHeader("Accept");
        System.out.println("获取请求头 - Accept : "+header);

        return "OK";
    }
}
